package cn.edu.zjgsu.ito.service;

import java.util.List;

import cn.edu.zjgsu.ito.model.LoginModel;

import com.jfinal.kit.EncryptionKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class LoginService
/*
 * 张虎涛
 * 2016/06/01
 */
{
	public Record validatorLoginStu(String username, String password) {
		password = EncryptionKit.md5Encrypt(password);//md5加密处理
		Record list=Db.findFirst(LoginModel.dao.selectLoginStuSql,username);
		if(list==null||list.equals(""))
		{
			//未找到该学生
			return null;
		}
		//检测学生信息是否失效
		if(list.get("sPwd").equals(password)){
			
			Record check=Db.findFirst(LoginModel.dao.checkLoginStuSql,username);
			
			if(check.get("studentStatus").equals(0)){
				
			return list;
			}else{
				return null;
			}
		}
		else{
			//学生信息失效
			return null;
		}
		
	}

	public Record validatorLoginAdmin(String username, String password) {
		password = EncryptionKit.md5Encrypt(password);
		Record record=Db.findFirst(LoginModel.dao.selectLoginAdminSql,username);
		if(record==null)
		{
			return null;
		}
		else	
		{
			if(record.get("aPwd").equals(password)){
				return record;
			}
			else{
				//密码不匹配
				return null;
			}
		}
	}
	
	public Record validatorLoginTea(String username, String password) {
		password = EncryptionKit.md5Encrypt(password);
		Record record=Db.findFirst(LoginModel.dao.selectLoginTeaSql,username);
		if(record==null)
		{
			return null;
		}
		else	
		{			
			if(record.getStr("tPwd").equals(password)){
				return record;
			}
			else{			
				return null;
			}
		}
	}

}
